
using System;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using Evaluant.Uss;
using Evaluant.Uss.ObjectContext;

		

namespace Model
{
		
	public partial interface IPerson
	{
		string Id { get; set; }
		System.String Name { get; set; }
		System.String FirstName { get; set; }
		
	}
	
  
  [Serializable]
  public partial class PersonCollection : IPersistableCollection<Person>
	{
		public PersonCollection() : base()
    {
    }

    public PersonCollection (ObjectContext persistenceManager, IPersistable parent, string role, IEnumerable<Person> data): base(persistenceManager, parent, role, data)
    {
    }
	}

	[Serializable]
	public partial class Person :  IPersistable, IPerson 
	{		
	
		[NonSerialized]
		protected Entity _Entity;
		
		[NonSerialized]
		protected ObjectContext _PersistenceManager;
		
		Entity IPersistable.Entity
		{
			get
			{
				return _Entity;
			}
			set
			{
				_Entity = value;
			}
		}
		
		ObjectContext IPersistable.ObjectContext
		{
			get
			{
				return _PersistenceManager;
			}
			set
			{
				_PersistenceManager = value;
			}
		}
		
		public string Id
		{
			get
			{
				return _Entity.Id;
			}
			set
			{
				_Entity.Id = value;
			}
		}
		
		~Person()
		{
			if(_PersistenceManager != null)
				_PersistenceManager.RemoveFromCache(this);
		}
	
		void IPersistable.TrackChildren()
		{
			// if the object is not tracked there is nothing to do
			if(_PersistenceManager == null)
				return;
	
		}
		
	
    protected System.String _Name;

    public System.String Name
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("Name"))
          _Name = (System.String)this._Entity["Name"];
          
        return _Name;
      }

      set
      {
        _Name = value;
        if(_Entity != null)
			this._Entity["Name"] = value;
      }
    }
    
    protected System.String _FirstName;

    public System.String FirstName
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("FirstName"))
          _FirstName = (System.String)this._Entity["FirstName"];
          
        return _FirstName;
      }

      set
      {
        _FirstName = value;
        if(_Entity != null)
			this._Entity["FirstName"] = value;
      }
    }
    
		public Person ()
		{
			
			this._Entity = new Entity(ObjectContext.ConvertNamespaceDomainToEuss(this.GetType().FullName));
		}

		public Person (Entity e)
		{
			this._Entity = e;
		}

		[Serializable]
		public class ParentRelationships
		{
			private IPersistable _Owner;
	
			public ParentRelationships()
			{
			}
			
			public ParentRelationships(IPersistable o)
			{
				_Owner = o;
			}
		
		}
	}
	
	public partial interface IEmployee
	{
		string Id { get; set; }
		System.Int32 Salary { get; set; }
		
	}
	
  
  [Serializable]
  public partial class EmployeeCollection : IPersistableCollection<Employee>
	{
		public EmployeeCollection() : base()
    {
    }

    public EmployeeCollection (ObjectContext persistenceManager, IPersistable parent, string role, IEnumerable<Employee> data): base(persistenceManager, parent, role, data)
    {
    }
	}

	[Serializable]
	public partial class Employee : Person, IPersistable, IEmployee 
	{		
	
		void IPersistable.TrackChildren()
		{
			// if the object is not tracked there is nothing to do
			if(_PersistenceManager == null)
				return;
	
		}
		
	
    protected System.Int32 _Salary;

    public System.Int32 Salary
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("Salary"))
          _Salary = (System.Int32)this._Entity["Salary"];
          
        return _Salary;
      }

      set
      {
        _Salary = value;
        if(_Entity != null)
			this._Entity["Salary"] = value;
      }
    }
    
		public Employee ()
		{
			
			this._Entity = new Entity(ObjectContext.ConvertNamespaceDomainToEuss(this.GetType().FullName));
		}

		public Employee (Entity e)
		{
			this._Entity = e;
		}

		[Serializable]
		public new class ParentRelationships
		{
			private IPersistable _Owner;
	
			public ParentRelationships()
			{
			}
			
			public ParentRelationships(IPersistable o)
			{
				_Owner = o;
			}
		
		}
	}
	
	public partial interface ICompany
	{
		string Id { get; set; }
		System.String Chairman { get; set; }
		System.String Name { get; set; }
		
		IEnumerable<IEmployee>  Employees { get; }

	}
	
  
  [Serializable]
  public partial class CompanyCollection : IPersistableCollection<Company>
	{
		public CompanyCollection() : base()
    {
    }

    public CompanyCollection (ObjectContext persistenceManager, IPersistable parent, string role, IEnumerable<Company> data): base(persistenceManager, parent, role, data)
    {
    }
	}

	[Serializable]
	public partial class Company :  IPersistable, ICompany 
	{		
	
		[NonSerialized]
		protected Entity _Entity;
		
		[NonSerialized]
		protected ObjectContext _PersistenceManager;
		
		Entity IPersistable.Entity
		{
			get
			{
				return _Entity;
			}
			set
			{
				_Entity = value;
			}
		}
		
		ObjectContext IPersistable.ObjectContext
		{
			get
			{
				return _PersistenceManager;
			}
			set
			{
				_PersistenceManager = value;
			}
		}
		
		public string Id
		{
			get
			{
				return _Entity.Id;
			}
			set
			{
				_Entity.Id = value;
			}
		}
		
		~Company()
		{
			if(_PersistenceManager != null)
				_PersistenceManager.RemoveFromCache(this);
		}
	
		void IPersistable.TrackChildren()
		{
			// if the object is not tracked there is nothing to do
			if(_PersistenceManager == null)
				return;
	
			if(_Employees != null)
				_PersistenceManager.TrackObject(_Employees);
		
		}
		
	
    protected System.String _Chairman;

    public System.String Chairman
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("Chairman"))
          _Chairman = (System.String)this._Entity["Chairman"];
          
        return _Chairman;
      }

      set
      {
        _Chairman = value;
        if(_Entity != null)
			this._Entity["Chairman"] = value;
      }
    }
    
    protected System.String _Name;

    public System.String Name
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("Name"))
          _Name = (System.String)this._Entity["Name"];
          
        return _Name;
      }

      set
      {
        _Name = value;
        if(_Entity != null)
			this._Entity["Name"] = value;
      }
    }
    
    protected EmployeeCollection _Employees;

    public EmployeeCollection Employees
    {
      get
      {
        if(_Employees == null)
        {
          // Inferred relationships
          EntitySet entities = _Entity.GetEntitySet("Employees");
          List<Employee> items = entities.Count == 0 ? null : _PersistenceManager.LoadWithEntities<Employee>(entities);

          _Employees = new EmployeeCollection(_PersistenceManager, this, "Employees", items);
        }
        return _Employees;
      }

      set // Defined for Serializable() compatibility only
      {
        _Employees = value;
      }
    }

		IEnumerable<IEmployee> ICompany.Employees
		{	                
			get 
			{ 
				foreach(IEmployee item in Employees) 
					yield return item;
			}
		}
	
		public Company ()
		{
			
			this._Entity = new Entity(ObjectContext.ConvertNamespaceDomainToEuss(this.GetType().FullName));
		}

		public Company (Entity e)
		{
			this._Entity = e;
		}

		[Serializable]
		public class ParentRelationships
		{
			private IPersistable _Owner;
	
			public ParentRelationships()
			{
			}
			
			public ParentRelationships(IPersistable o)
			{
				_Owner = o;
			}
		
		}
	}

}
